package com.zzyl.nursing.controller;

import java.util.List;

import com.huaweicloud.sdk.iotda.v5.model.ServiceCapability;
import com.zzyl.nursing.dto.DeviceDto;
import com.zzyl.nursing.vo.ProductVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.aspectj.weaver.loadtime.Aj;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.zzyl.common.core.controller.BaseController;
import com.zzyl.common.core.domain.AjaxResult;
import com.zzyl.nursing.domain.Device;
import com.zzyl.nursing.service.IDeviceService;
import com.zzyl.common.core.page.TableDataInfo;

/**
 * 设备Controller
 *
 * @author ruoyi
 * @date 2025-08-01
 */
@RestController
@RequestMapping("/nursing/device")
@Api(tags = "设备相关接口")
public class DeviceController extends BaseController {
    @Autowired
    private IDeviceService deviceService;

    /**
     * 查询设备列表
     */
    @PreAuthorize("@ss.hasPermi('nursing:device:list')")
    @GetMapping("/list")
    @ApiOperation(value = "获取设备列表")
    public TableDataInfo<List<Device>> list(Device device) {
        startPage();
        List<Device> list = deviceService.selectDeviceList(device);
        return getDataTable(list);
    }

    @PostMapping("/syncProductList")
    @ApiOperation("同步产品列表")
    public AjaxResult syncProductList() {
        deviceService.syncProductList();
        return success();
    }

    @GetMapping("/allProduct")
    public AjaxResult allProduct() {
        List<ProductVo> list = deviceService.allProduct();
        return AjaxResult.success(list);
    }
    @PostMapping("/register")
    @ApiOperation("设备注册")
    public AjaxResult register(@RequestBody DeviceDto dto) {
        deviceService.register(dto);
        return success();
    }
    @GetMapping("/{iotId}")
    @ApiOperation("查询设备详情数据")
    public AjaxResult getInfo(@PathVariable String iotId){

        return AjaxResult.success(deviceService.queryDeviceDetail(iotId));
    }
    @GetMapping("/queryServiceProperties/{iotId}")
    @ApiOperation("查询设备上报的数据")
    public AjaxResult queryServiceProperties(@PathVariable String iotId){
        return AjaxResult.success(deviceService.queryServiceProperties(iotId));
    }
    @PutMapping
    @ApiOperation("修改设备")
    public AjaxResult edit(@RequestBody DeviceDto dto) {
        deviceService.edit(dto);
        return success();
    }
    @DeleteMapping("/{iotId}")
    @ApiOperation("删除设备")
    public AjaxResult remove(@PathVariable String iotId) {
        deviceService.deleteDevice(iotId);
        return success();
    }
    @GetMapping("/queryProduct/{productKey}")
    public AjaxResult queryProject(@PathVariable String productKey) {
        List<ServiceCapability> list = deviceService.queryProject(productKey);
        return success(list);
    }
}
